package com.huike.stock_analysis.controller;
/**
 * 
 * @author mzLEI
 * 技术指标接口
 */

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huike.stock_analysis.entity.Stock;
import com.huike.stock_analysis.service.TechniqueService;


@RestController
@CrossOrigin(value = "*")
@RequestMapping("/technique")
public class TechniqueController {
	@Autowired
	private TechniqueService tService;
	//股票基本信息
	@RequestMapping("/base")
	public String base(String stock) {
		if(stock == null) return "null";
		Stock stock1 = tService.base(stock);
		//System.out.println(stock1.getDate());
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(stock1);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
		
	}
	//均线
	@RequestMapping("/ma")
	public String ma(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.ma(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//EMA
	@RequestMapping("/ema")
	public String ema(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.ema(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	
	//布林线
	@RequestMapping("/boll")
	public String boll(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.boll(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	
	//涨跌幅
	@RequestMapping("/change5")
	public String change(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.change5(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	
	}
	//MACD
	@RequestMapping("/macd")
	public String macd(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.macd(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	//RSV
	@RequestMapping("/rsv")
	public String rsv(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.rsv(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	
	}
	//KDJ
	@RequestMapping("/kdj")
	public String kdj(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.kdj(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//rsi
	@RequestMapping("/rsi")
	public String rsi(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.rsi(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//dif
	@RequestMapping("/dif")
	public String dif(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.dif(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//成交量
	@RequestMapping("/cjl")
	public String cjl(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.cjl(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//历史波动率+行业平均
	@RequestMapping("/historyRatio")
	public String historyRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.historyRatio(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	

	//日K
	@RequestMapping("/day")
	public String day(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = tService.dayK(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

}
